﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.ObjectModel;
using DeepTime.DL;
using System.Collections;
using System.Collections.Generic;
using DeepTime.Shared.Entities;
using DeepTime.DataSources.DL;
using DeepTime.DL.DataModels;

namespace DeepTime.Web.Services
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class UploadedImageMetaData
    {
        [OperationContract]
        public UploadedImageMetaDataEntity GetUploadedImage(string rowKey, string partitionKey)
        {
            //
            // Get item
            //
            UploadedImageMetaDataDataSource uploadedImageMetaDataDataSource = new UploadedImageMetaDataDataSource();
            UploadedImageMetaDataDataModel data = uploadedImageMetaDataDataSource.Select().Where(d => d.PartitionKey == partitionKey && d.RowKey == rowKey).FirstOrDefault();

            if (data != null)
            {
                return data.GetEntity();
            }
            else
            {
                return new UploadedImageMetaDataEntity();
            }
        }

        [OperationContract]
        public ObservableCollection<UploadedImageMetaDataEntity> GetUploadedImages()
        {
            //
            // Get all uploaded images meta data
            //
            UploadedImageMetaDataDataSource uploadedImageMetaDataDataSource = new UploadedImageMetaDataDataSource();
            IEnumerable<UploadedImageMetaDataEntity> items = from img in uploadedImageMetaDataDataSource.Select()
                                                             select img.GetEntity();

            return new ObservableCollection<UploadedImageMetaDataEntity>(items);
        }
    }
}
